
package com.iocup.keybastion.authorize.parser;


import com.iocup.keybastion.annotion.HasPermission;
import com.iocup.keybastion.authorize.decision.DecisionType;
import com.iocup.keybastion.authorize.element.AuthElement;

/**
 * @author xyjxust
 * @create 2022/3/2 13:44
 **/
public class HasPermissionElementParser implements AnnotationElementParser<HasPermission> {

    @Override
    public AuthElement parser(String key, HasPermission hasPermission) {
        return AuthElement.build()
                .code(key)
                .type(getType())
                .putParam(HasPermission.VALUE, String.join(",",hasPermission.value()))
                .putParam(HasPermission.LOGICAL, hasPermission.logical().name());
    }

    @Override
    public String getType() {
        return DecisionType.hasPermission.name();
    }
}
